package com.sea.base.ext.global

import android.app.Application

/**
 * Author: Wu Chang
 * 缓存全局的Context提供给各模块需要的方法使用
 * Date: 2023/3/27 9:56
 */
class BaseApp(
    /**
     * 从Application初始化全局引用的参数
     */
    val context: Application,
    /**
     * 是不是debug
     */
    @JvmField
    val isDebug: Boolean,
) {

    companion object {
        private var _ins: BaseApp? = null

        @JvmStatic
        val instance: BaseApp
            get() {
                return _ins ?: throw IllegalStateException("未初始化过，请在宿主app先调用setInstance")
            }

        @JvmStatic
        @Synchronized
        fun setInstance(
            app: Application,
            isDebug: Boolean
        ) {
            if (_ins != null) return
            _ins = BaseApp(app, isDebug)
        }
    }
}